/**
 * 给定N, X, Y, 定义一个排列的得分为：
 * (p[x] + p[2x] + ...) - (p[y] + p[2y] + ...)
 * 求最大的得分
 * 只需要把N,N-1,...安排给x
 * 把1,2,...安排给y即可
 * 另外注意到不要给P[lcm(x, y)]等安排
 * 计算出应该给x的数量以及应该给y的数量即可
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using Real = long double;
using llt = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

#ifndef ONLINE_JUDGE
int const SZ = 101;
#else
int const SZ = 110;
#endif

llt N, X, Y;

llt proc(){
	if(X == Y) return 0;

	llt g = __gcd(X, Y);
	llt m = X / g * Y;

	llt xc = N / X;
	llt yc = N / Y;
	llt cc = N / m;

	xc -= cc;
	yc -= cc;

	llt xx = (N + N - xc + 1) * xc / 2;
	llt yy = (1 + yc) * yc / 2;
	return xx - yy;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase; cin >> nofkase;
	while(nofkase--){
        cin >> N >> X >> Y;
		cout << proc() << endl;
	}
    return 0;
}